<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>
    </title>
    <meta name="format-detection" content="telephone=no, address=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <script src="__FRONT__/js/require.js"></script>
    <script type="text/javascript" src="__FRONT__/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="__FRONT__/js/common.js"></script>
    <link href="__FRONT__/css/bootstrap.min.css" rel="stylesheet">
    <link href="__FRONT__/css/common.min.css" rel="stylesheet">
    <style>
        .send_button{
            color: #fff;
            background-color: #04be02;
            border: 1px solid #04be02;
        }
    </style>
</head>
<body class="mui-ios mui-ios-11 mui-ios-11-0">
<div class="container container-fill">
    <div class="mui-content mc-login">
        <div class="avatar mui-text-center">
            <img src="__FRONT__/img/headimg_1.jpg" class="mui-img-circle">
        </div>
        <div class="mui-input-group" id="register-basic">
            <div class="mui-input-row">
                <label class="mui-label-icon"><i class="fa fa-user"></i></label>
                <input name="username" type="text" placeholder="请填写手机号">
            </div>
            <div class="mui-input-row">
                <label class="mui-label-icon"><i class="fa fa-lock"></i></label>
                <input name="password" type="password" placeholder="密码" class="mui-input-password"
                       data-input-password="2"><span class="mui-icon mui-icon-eye"></span>
            </div>
            <div class="mui-input-row">
                <label class="mui-label-icon"><i class="fa fa-lock"></i></label>
                <input name="repassword" type="password" placeholder="确认密码" class="mui-input-password"
                       data-input-password="3"><span class="mui-icon mui-icon-eye"></span>
            </div>
            <div class="mui-input-row">
                <label class="mui-label-icon"><i class="fa fa-key"></i></label>
                <input name="verycode" type="text" placeholder="验证码" style="width: 50%;float:left;">
                <input  type="button" class="mui-btn mui-btn-success send_button send-code"
                       uniacid="1" style=" font-size:12px;width:30%;color: #fff;background-color: #04be02;border: 1px solid #04be02; border-radius: 5px" value="获取验证码">
            </div>
            {if(!$invcode)}
            <div class="mui-input-row">
                <label class="mui-label-icon"><i class="fa fa-check"></i></label>
                <input name="invcode" id="invcode" type="text" placeholder="邀请码" class="mui-input-password"
                       data-input-password="3"><span class="mui-icon"></span>
            </div>
            {/if}
        </div>
        <div class="mui-content-padded">
            <button class="mui-btn mui-btn-success mui-btn-block register-basic reg_btn" type="button">注册</button>
        </div>
        <div class="mui-content-padded">
            <div class="mui-text-center mui-mt15">
                <a href="{:url('user/index')}">立即登录</a>
                <span class="mui-ml5 mui-mr5 mui-text-muted">|</span>
                <a href="###">找回密码</a>
            </div>
        </div>
    </div>
    <div class="msg-box"></div>
</div>
<script>
    $(function () {

        $(document).on('click', '.send-code', function () {
            var username = $('input[name="username"]').val();
            var uniacid = $(this).attr('uniacid');
            if (!username) {
                showmsg('请输入手机号', 1);
                return;
            }
            if (!/^1[3|4|5|7|8][0-9]{9}$/.test(username)) {
                showmsg('手机号格式错误', 1);
                return;
            }
            var params = {};
            params.mobile = username;
            params.uniacid = uniacid;
            $.post("{:url('user/getRegCode')}", params, function (dat) {

                if (dat.code == 0) {
                    showmsg(dat.msg, 0);
                } else {
                    showmsg(dat.msg, 1);
                }
            });

            var downcount = 60;
            $('.send-code').attr('value', downcount + '秒后重新获取');
            var timer = setInterval(function () {
                downcount--;
                if (downcount <= 0) {
                    clearInterval(timer);
                    downcount = 60;
                    $('.send-code').attr('value', '获取验证码');
                    $('.send-code').attr('uniacid', '1');
                } else {
                    $('.send-code').attr('value', downcount + "秒后重新获取");
                    $('.send-code').attr('uniacid', '0');
                }
            }, 1000);

        });
        $(document).on('click', '.js-code', function () {
            var username = $('#register-code input[name="username"]').val();
            var password = $('#register-code input[name="password"]').val();
            audit_password = '';
            audit_repassword = '';
            audit_password = $('#register-code input[name="audit-password"]').val();
            audit_repassword = $('#register-code input[name="audit-password"]').val();
            if (!username) {
                util.toast('请输入手机号', '', 'error');
                return;
            }
            if (!password) {
                util.toast('请输入验证码', '', 'error');
                return;
            }
            var href = "./index.php?i=1&c=auth&a=register&code=1&wxref=mp.weixin.qq.com#wechat_redirect";
            $.post(href, {
                'username': username,
                'password': password,
                'audit_password': audit_password,
                'audit_repassword': audit_repassword
            }, function (data) {
                data = $.parseJSON(data);
                if (data.type == 'success') {
                    location.reload();
                } else {
                    mui.min.toast(data.message);
                }
            })
        });

        $('.mui-icon-eye').click(function () {
            if ($(this).hasClass('mui-active')) {
                $(this).prev('input').attr('type', 'password');
                $(this).removeClass('mui-active');
            } else {
                $(this).prev('input').attr('type', 'text');
                $(this).addClass('mui-active');
            }
        });
        $(document).on('click', '.register-basic', function () {
            var username = $('input[name="username"]').val();
            var password = $('input[name="password"]').val();
            var repassword = $('input[name="repassword"]').val();
            var verycode = $('input[name="verycode"]').val();
            var pid={$pid};

            if (!username || !password || !repassword) {
                showmsg('用户名或密码为空', 1);
                return;
            }
            if (!verycode) {
                showmsg('验证码不能为空', 1);
                return;
            }
            if($('#invcode').length>0){
                var invcode = $('input[name="invcode"]').val();
                if(!invcode){
                    showmsg('邀请码不能为空',1);
                    return;
                }
            }

            var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
            if (!myreg.test(username)) {
                showmsg('请输入正确的手机号码', 1);
                return false;
            }
            if (password.length < 6) {
                showmsg('密码不能小于六位数', 1);
                return;
            }
            if (password !== repassword) {
                showmsg('两次密码输入不一致', 1);
                return;
            }

            var params = {};
            params.username = username;
            params.password = password;
            params.repassword = repassword;
            params.verycode = verycode;
            params.pid=pid;
            if(invcode){
                params.invcode = invcode;
            }

            var href = "{:url('user/user_reg')}";
            $.post(href, params, function(data) {

                if (data.code == 0) {
                    showmsg(data.msg,0,"{:url('user/index')}");

                } else {
                    showmsg(data.msg, 1);
                }
            })
        })
    });
</script>
<script>


    var countdown = 60;

    function sendemail() {
        var obj = $("#code_btn");
        settime(obj);
    }

    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            obj.attr('disabled', false);
            //obj.removeattr("disabled");
            obj.val("获取验证码");
            countdown = 60;
            return;
        } else {
            obj.attr('disabled', true);
            obj.val("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function () {
                settime(obj)
            }
            , 1000)
    }

</script>
</body>
</html>